//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <mmu.h>
#include <init.h>

const uint_t c_uMaxNumberOfMemoryZones          = 1;
const uint_t c_uMaxNumberOfMemoryHoles          = 1;

EXTERN_C_BEGIN

STATIC DECL_DATAINIT MemoryZone    s_memoryZones[c_uMaxNumberOfMemoryZones];
STATIC DECL_DATAINIT MemoryHole    s_memoryHoles[c_uMaxNumberOfMemoryHoles];

EXTERN_C_END

STATIC DECL_CODEINIT void GetInitStack();
STATIC DECL_CODEINIT void GetMemoryZones();

EXTERN_C DECL_CODEINIT void CDECL InitMemoryZones()
{
    GetInitStack();

    GetMemoryZones();
}

STATIC DECL_CODEINIT void GetInitStack()
{
    bsp.regionOfInitStack.uBasePageNo = PHYSADDR_TO_PAGENO(PHYSADDR(0x80001000));
    bsp.regionOfInitStack.uLimitPageNo = PHYSADDR_TO_PAGENO(PHYSADDR(0x800FE000));
}

STATIC DECL_CODEINIT void GetMemoryZones()
{
    // It's 128M
    bsp.pMemoryZones = s_memoryZones;
    bsp.pMemoryHoles = s_memoryHoles;
    
    s_memoryZones[0].uBasePageNo    = PHYSADDR_TO_PAGENO(PHYSADDR(0x80000000));
    s_memoryZones[0].uLimitPageNo   = PHYSADDR_TO_PAGENO(PHYSADDR(0x88000000));
    bsp.uNumberOfMemoryZones = 1;

    bsp.uDmaPreferredZoneNo = 0;
    bsp.uKernelPreferredZoneNo = 0;
    bsp.uUserPreferredZoneNo = 0;

    // The hole is ready for the exception code
    bsp.uNumberOfMemoryHoles = 1;
    s_memoryHoles[0].uBasePageNo    = PHYSADDR_TO_PAGENO(PHYSADDR(0x80000000));
    s_memoryHoles[0].uLimitPageNo   =
        PHYSADDR_TO_PAGENO(PHYSADDR(0x80000000 + PAGE_SIZE));
}
